# 592. 门牌制作
# https://www.lanqiao.cn/problems/592/learning/?page=1&first_category_id=1&second_category_id=3
# Date: 2025/2/15
from collections import Counter


def count_num_two(num: int):
    cnt = 0
    for i in range(1, num + 1):
        s = str(i)
        if "2" in s:
            cnt += Counter(s).get("2")
    return cnt


if __name__ == '__main__':
    print(count_num_two(12))  # 2 -> 2 12
    print(count_num_two(23))  # 7 -> 2 12 20 21 22 23
    print(count_num_two(2020))  # 624
